package com.ky.manage.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ky.manage.R;
import com.ky.manage.model.response.EmergencyInfoListResp;
import com.ky.manage.utils.ImageLoader.ImageLoaderUtils;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * 应急 adapter
 */
public class EmergencyInfoAdapter extends BaseQuickAdapter<EmergencyInfoListResp.EmergencyInfo, BaseViewHolder> {
    private List<EmergencyInfoListResp.EmergencyInfo> list;
    private Context context;

    public EmergencyInfoAdapter(Context context, int layoutId, List<EmergencyInfoListResp.EmergencyInfo> list) {
        super(layoutId, list);
        this.list = list;
        this.context = context;
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder , EmergencyInfoListResp.EmergencyInfo emergencyInfo) {
        TextView descTv = baseViewHolder.getView(R.id.desc_tv);
        ImageView coverIv = baseViewHolder.getView(R.id.cover_iv);
        TextView uploadInfoIv = baseViewHolder.getView(R.id.upload_info_tv);
        if (null == emergencyInfo) {
            return;
        }
        descTv.setText(emergencyInfo.simpleDesc);
        uploadInfoIv.setText(emergencyInfo.createBy + "  " + emergencyInfo.createTime);
        String coverUrl = TextUtils.isEmpty(emergencyInfo.coverUrl) ? (TextUtils.isEmpty(emergencyInfo.localePic)
                ? "" : emergencyInfo.localePic) : emergencyInfo.coverUrl;
        if (TextUtils.isEmpty(coverUrl)) {
            coverIv.setVisibility(View.GONE);
        } else {
            ImageLoaderUtils.loadImage(context, coverUrl, coverIv);
            coverIv.setVisibility(View.VISIBLE);
        }
    }
}
